package org.adamtacy.client.ui.effects;

import java.util.Iterator;
import java.util.Vector;

import com.google.gwt.dom.client.Element;


public abstract class ParallelEffect extends Effect{

	protected Vector<Effect> effects;
	
	protected boolean keepEffectsInSync = true;
	
	public void addEffect(Effect newEffect){
		if(effects==null){
			effects = new Vector<Effect>();
		}
		effects.add(newEffect);
	}
	
	public void removeEffect(Effect effect){
		if(effects!=null){
			if(effects.contains(effect))effects.remove(effect);
		}
	}
	
	public void setEffectElement(Element el) {
		super.setEffectElement(el);
	    for (Iterator<Effect> iter = effects.iterator(); iter.hasNext();){
	        Effect e = iter.next();
	        e.setEffectElement(el);
	    }
	}
	
	public void addEffectElement(Element el) {
		super.addEffectElement(el);
	    for (Iterator<Effect> iter = effects.iterator(); iter.hasNext();){
	        Effect e = iter.next();
	        e.addEffectElement(el);
	    }
	}
	
	public void onUpdate(double progress){
		super.onUpdate(progress);
	    for (Iterator<Effect> iter = effects.iterator(); iter.hasNext();){
	        Effect e = iter.next();
	        e.onUpdate(progress);
	    }
	}
	
	
	@Override
	public void setUpEffect() {
	    for (Iterator<Effect> iter = effects.iterator(); iter.hasNext();){
	        Effect e = iter.next();
	        e.setUpEffect();
	    }		
	}
	
	@Override
	public void tearDownEffect(Element el) {
		for(Effect e:this.effects) e.tearDownEffect();
	}

}
